﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<jsp:useBean id="dateValue" class="java.util.Date"/>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="<%=basePath%>">
    <!-- jsp文件头和头部 -->
    <%@ include file="../admin/top.jsp" %>
    <style>
        table tr td img {
            height: 25px;
            border-radius: 8%;
        }
    </style>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <form action="refundOrder/list" method="post" name="refundOrderForm" id="refundOrderForm">
                    <input type="hidden" name="menuId" value="${page.menuId}">
                    <table style="width: 92%">
                        <tr>
                            <td style="width: 14%">
                                <span class="input-icon">
                                    <input style="margin-top: 0px;width: 85%;" id="refundId" autocomplete="off" type="text"
                                           name="searchValue" value="${page.searchValue}" placeholder="退款订单号"/>
                                </span>
                            </td>
                            <td style="width: 14%">
                                   <span class="input-icon">
                                     <input style="margin-top: 0px;width: 85%" autocomplete="off" type="text" id="outTradeNo"
                                            name="outTradeNo" value="${outTradeNo}" placeholder="订单号"/>
                                   </span>
                            </td>
                            <td style="width: 14%">
                                   <span class="input-icon">
                                     <input style="margin-top: 0px;width: 85%" autocomplete="off" type="text" id="transactionId"
                                            name="transactionId" value="${transactionId}" placeholder="支付订单号"/>
                                   </span>
                            </td>
                            <td style="width:18%">
									<span>
                                       <%-- <label>开始日期：</label>--%>
										<input class="span10 date-picker" name="startTime" id="startTime"
                                               value="${startTime}" type="text" data-date-format="yyyy-mm-dd"
                                               readonly="readonly"
                                               <%--style="width:88px;display: table-cell;font-size: 12px;float: left"--%>
                                               style="width:46%;margin-left:1%;display: table-cell;font-size: 12px;float: left"
                                               placeholder="开始日期" title="开始日期"/>
                                         <%--<label>结束日期</label>--%>
										<input class="span10 date-picker" name="endTime" id="endTime" value="${endTime}"
                                               type="text" data-date-format="yyyy-mm-dd" readonly="readonly"
                                               <%--style="width:88px;display: table-cell;font-size: 12px;float:left;"--%>
                                               style="width:46%;display: table-cell;font-size: 12px;float:left;"
                                               placeholder="结束日期" title="结束日期"/>
									</span>
                            </td>
                            <td style="vertical-align:top;width:12%;">
                                <select id="refundType" name="refundType" data-values="${refundType}"
                                        data-placeholder="请选择支付类型" style="vertical-align:top;width:95%;">
                                    <option value="">选择退款类型</option>
                                    <option value="alipayRefund" <c:if test="${refundType == 'alipayRefund'}">selected</c:if>>支付宝</option>
                                    <option value="wechatRefund" <c:if test="${refundType == 'wechatRefund'}">selected</c:if>>微信</option>
                                    <option value="appleRefund" <c:if test="${refundType == 'appleRefund'}">selected</c:if>>苹果</option>
                                </select>
                            </td>
                            <td style="vertical-align:top;width: 12%">
                                <select  id="orderType" name="orderType" data-values="${orderType}"
                                         data-placeholder="请选择购买类型" style="vertical-align:top;width:95%;" onchange="updateProductType()">
                                    <option value="">选择购买类型</option>
                                    <option value="0" <c:if test="${orderType == '0'}">selected</c:if>>会员</option>
                                    <option value="1" <c:if test="${orderType == '1'}">selected</c:if>>金币</option>
                                </select>
                            </td>
                            <td style="vertical-align:top;width: 20%">
                                <select id="productType" name="productType" data-values="${productType}" data-placeholder="请选择会员/金币类型" style="vertical-align:top;width:95%;">
                                    <option value="">选择选择会员/金币类型</option>
                                </select>
                            </td>
                            <td style="vertical-align:top;width:4%;">
                                <button class="btn btn-mini btn-light" onclick="search();" title="检索">
                                    <i id="nav-search-icon" class="icon-search"></i>
                                </button>
                            </td>
                            <td style="vertical-align:top;width: 6%">
                                <c:if test="${fn:contains(butSet, 'import')}">
                                    <a class="btn btn-small btn-success" onclick="importData();" style="margin-left:10px;width: 60px;">导出数据</a>
                                </c:if>
                            </td>
                           <%-- <td style="vertical-align:top;width: 6%">
                                  <c:if test="${fn:contains(butSet, 'update')}">
                                    <a class="btn btn-small btn-success" onclick="updateData();" style="margin-left:10px;width: 60px;">更新</a>
                                  </c:if>
                            </td>--%>
                        </tr>
                        <tr>
                           <%-- <td>
                                <a class="btn btn-small btn-success" style="margin-left:5px;margin-bottom:10px;width:100px;" onclick="queryRefundTotal();" >退款总金额</a>
                            </td>--%>
                            <td>
                                <span id="refundTotal" style="margin-left:5px;margin-bottom:10px;">
                                    退款总金额：<c:out value="${refundTotal}"/>
                                </span>
                            </td>
                        </tr>
                    </table>
                    <!-- 检索  -->
                    <table id="table_report" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>退款单号</th>
                            <th>订单号</th>
                            <th>支付订单号</th>
                            <th>购买类型</th>
                            <th>退款状态</th>
                            <th>退款方式</th>
                            <th>退款金额</th>
                            <th>订单总金额</th>
                            <th>币种</th>
                            <th>退款原因</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <!-- 开始循环 -->
                        <c:choose>
                            <c:when test="${not empty refundOrders}">
                                <c:forEach items="${refundOrders}" var="refundApply">
                                    <tr style="text-align: center">
                                        <td>${refundApply.id }</td>
                                        <td>${refundApply.outTradeNo}</td>
                                        <td>${refundApply.transactionId}</td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${refundApply.orderType == 0}">
                                                    会员
                                                </c:when>
                                                <c:when test="${refundApply.orderType == 1}">
                                                    金币
                                                </c:when>
                                                <c:otherwise>
                                                    退款失败
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>
                                            <c:choose>
                                                <c:when test="${refundApply.status == 'SUCCESS'}">
                                                    退款成功
                                                </c:when>
                                                <c:when test="${refundApply.status == 'CLOSED'}">
                                                    退款失败
                                                </c:when>
                                                <c:when test="${refundApply.status == 'PROCESSING'}">
                                                    退款中
                                                </c:when>
                                                <c:when test="${refundApply.status == 'ABNORMAL'}">
                                                    退款异常
                                                </c:when>
                                                <c:otherwise>
                                                    退款失败
                                                </c:otherwise>
                                            </c:choose>
                                        </td>
                                        <td>${refundApply.refundMethod}</td>
                                        <td>${refundApply.refund}</td>
                                        <td>${refundApply.total}</td>
                                        <td>${refundApply.currency}</td>
                                        <td>${refundApply.refundReason}</td>
                                        <td><fmt:formatDate value="${refundApply.createTime }" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                                        <td>
                                            <c:if test="${fn:contains(butSet, 'queryRefundOrder') && refundApply.status == 'PROCESSING' }">
                                                <a class="btn btn-mini" onclick="operateDev('${refundApply.id}', 0)">查询退款订单</a>
                                            </c:if>
                                        </td>
                                    </tr>
                                </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <tr class="main_info">
                                    <td colspan="12" class="center">没有相关数据</td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        </tbody>
                    </table>
                    <div class="page-header position-relative">
                        <table style="width:100%;">
                            <tr>
                                <td style="vertical-align:top;">
                                    <div class="pagination"
                                         style="float: right;padding-top: 0px;margin-top: 0px;">${page.pageStr}</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn btn-small btn-inverse">
    <i class="icon-double-angle-up icon-only"></i>
</a>
<!-- 引入 -->
<script type="text/javascript">window.jQuery || document.write("<script src='static/js/jquery-1.9.1.min.js'>\x3C/script>");</script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/ace-elements.min.js"></script>
<script src="static/js/ace.min.js"></script>

<script type="text/javascript" src="static/js/chosen.jquery.min.js"></script><!-- 下拉框 -->
<script type="text/javascript" src="static/js/bootstrap-datepicker.min.js"></script><!-- 日期框 -->
<script type="text/javascript" src="static/js/bootbox.min.js"></script><!-- 确认窗口 -->
<!-- 引入 -->
<script type="text/javascript" src="static/js/jquery.tips.js"></script><!--提示框-->
<script type="text/javascript">
    $(top.hangge());
    //检索
    function search() {
        top.jzts();
        $("#refundOrderForm").submit();
    }
    function operateDev(refundId, type) {
        top.jzts();
        var url = "<%=basePath%>refundOrder/refundStatus";
        var postParam = {"refundId": refundId};
        $.post(url, postParam, function (data) {
            top.Dialog.close();
            if (data.code == 200) {
                top.hangge();
                //刷新页面
                $("#refundOrderForm").submit();
            } else {
                alert("操作失败:"+data.msg);
            }
        });
    }

    //查询支付成功总金额
    function queryRefundTotal(){
        var url = "<%=basePath%>refundOrder/queryRefundTotal";
        $.post(url, function (data) {
            if (data.code == 200) {
                top.hangge();
                $("#refundTotal").text("退款总金额："+data.data);
            } else {
                alert("操作失败:"+data.msg)
            }
        });
    }

    //导出数据
    function importData(){
        var url = "<%=basePath%>refundOrder/import" +
            "?refundId=" + encodeURIComponent($("#refundId").val()) +
            "&outTradeNo=" + encodeURIComponent($("#outTradeNo").val()) +
            "&transactionId=" + encodeURIComponent($("#transactionId").val()) +
            "&orderType=" + encodeURIComponent($("#orderType").val()) +
            "&productType=" + encodeURIComponent($("#productType").val()) +
            "&startTime=" + encodeURIComponent($("#startTime").val()) +
            "&endTime=" + encodeURIComponent($("#endTime").val()) +
            "&refundType=" + encodeURIComponent($("#refundType").val()) ;
        window.open(url);
    }

    function updateData(){
        var url = "<%=basePath%>refundOrder/update";
        $.post(url, function (data) {
            if (data.code == 200) {
                top.jzts();
                $("#refundOrderForm").submit();
            } else {
                alert("操作失败:"+data.msg);
            }
        });
    }

    //更新产品
    function updateProductType() {
        var orderType = document.getElementById("orderType").value;
        var productTypeSelect = document.getElementById("productType");
        // 保存当前 productType 的值（默认值或者用户已选）
        var currentValue = "${productType}";
        // 清空旧选项
        productTypeSelect.innerHTML = "";
        // 添加默认提示项
        var defaultOption = document.createElement("option");
        defaultOption.value = "";
        defaultOption.text = "请选择会员/金币类型";
        productTypeSelect.appendChild(defaultOption);

        // 根据 orderType 添加不同选项
        if (orderType === "0") {
            // 会员选项
            addOption(productTypeSelect, "1", "月会员");
            addOption(productTypeSelect, "2", "年会员");
            addOption(productTypeSelect, "3", "永久会员");
            addOption(productTypeSelect, "4", "半年会员");
        } else if (orderType === "1") {
            // 金币选项
            addOption(productTypeSelect, "1", "白金");
            addOption(productTypeSelect, "2", "黄金");
            addOption(productTypeSelect, "3", "红金");
            addOption(productTypeSelect, "4", "紫金");
            addOption(productTypeSelect, "5", "黑金");
        }
        if(orderType && currentValue!=="null" && currentValue && currentValue !== "null") {
            // 设置默认选中（仅当选项存在时）
            {
                for (var i = 0; i < productTypeSelect.options.length; i++) {
                    if (productTypeSelect.options[i].value === currentValue) {
                        productTypeSelect.options[i].selected = true;
                        break;
                    }
                }
            }
        }
    }

    function addOption(select, value, text) {
        var option = document.createElement("option");
        option.value = value;
        option.text = text;
        select.appendChild(option);
    }

    // 页面加载时自动填充 productType 选项
    window.onload = function () {
        updateProductType(); // 根据当前 orderType 渲染 productType 的选项
    };
</script>

<script type="text/javascript">
    $(function () {
        //日期框
        $('.date-picker').datepicker({autoclose: true});
        //下拉框
        $(".chzn-select").chosen();
        $(".chzn-select-deselect").chosen({allow_single_deselect: true});
        //复选框
        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
        });
    });
</script>
</body>
</html>
